<template>
  <div>
    <el-form :model="FIndexCmsMenu" label-width="80px">
      <el-form-item label="菜单名称">
        <el-input v-model="FIndexCmsMenu.FMenuName"></el-input>
      </el-form-item>
      <el-form-item label="上级菜单">
        <el-cascader
          v-model="FIndexCmsMenu.FPMenuID"
          :options="FCmsMenuTreeList"
          :props="{ checkStrictly: true, emitPath: false }"
          filterable
          clearable
          placeholder="选择上级菜单"
        ></el-cascader>
      </el-form-item>
      <el-form-item label="菜单命令">
        <el-select v-model="FIndexCmsMenu.FMenuCmdMode" placeholder="请选择">
          <el-option
            v-for="item in FModeOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="菜单脚本">
        <el-input
          type="textarea"
          :rows="4"
          v-model="FIndexCmsMenu.FMenuCmdCode"
        ></el-input>
      </el-form-item>
    </el-form>
    <el-row>
      <el-button @click="onSave">保存</el-button>
      <el-button @click="onExit">退出</el-button>
    </el-row>
  </div>
</template>
<script lang="ts">
import { TBaseCmsMenu, TMyMenuCmdMode } from "@/baselib/module/cms/BaseCmsApi";
import TFormBase from "@/views/BaseForm";
import elmHelper from "../model/elmHelper";
export default class TFormCmsMenuEdit extends TFormBase {
  private FModeOptions: any = TMyMenuCmdMode;
  private FIndexCmsMenu: TBaseCmsMenu = new TBaseCmsMenu();
  private FCMSID: string = "";
  private FCmsMenuTreeList: any = [];
  public created() {
    let temp = this.zContextParams;
    if (temp.FCMSID) {
      this.FIndexCmsMenu = temp;
      if (this.$myStrHelper.stringIsEmptyYW(this.FIndexCmsMenu.FCMSID)) {
        this.$myMsgHelp.msgDialog("参数值不正确【FCMSID】值不可为空");
        return;
      }
      this.FCMSID = this.FIndexCmsMenu.FCMSID;
    } else {
      this.$myMsgHelp.msgDialog(
        "参数类型不正确,请传入参数[CmsMenu],类型[TBaseCmsMenu]"
      );
      return;
    }
    this.openData();
  }
  private async openData() {
    this.zIsOpenData = false;
    var lResultB = await this.$myBaseCms.GetCmsMenuList(this.FCMSID);
    if (!lResultB.resultSuccess) {
      this.$myMsgHelp.msgDialog(lResultB.resultMsg);
      return;
    }
    let tempList = lResultB.resultData;
    this.FCmsMenuTreeList = elmHelper.dataToElmTree(
      tempList,
      "FMenuID",
      "FPMenuID",
      "FMenuName",
      "FMenuID"
    );

    if (this.$myStrHelper.stringIsEmptyYW(this.FIndexCmsMenu.FMenuID)) {
      this.FIndexCmsMenu = new TBaseCmsMenu();
      this.FIndexCmsMenu.FCMSID = this.FCMSID;
      return;
    }
    var lResult = await this.$myBaseCms.GetCmsMenuByID(
      this.FIndexCmsMenu.FMenuID
    );
    if (!lResult.resultSuccess) {
      this.$myMsgHelp.msgDialog(lResult.resultMsg);
      return;
    }
    this.FIndexCmsMenu = lResult.resultData;

    this.zIsOpenData = true;
    this.$myMsgHelp.msgHintAutoClose("打开数据成功");
  }
  private async onSave() {
    let lResult = await this.$myBaseCms.SaveCmsMenu(this.FIndexCmsMenu);
    if (!lResult.resultSuccess) {
      this.$myMsgHelp.msgDialog(lResult.resultMsg);
      return;
    }
    if (typeof this.zContextOnCall == "function") {
      this.zContextOnCall("save", this.FIndexCmsMenu);
    }
  }
  private onExit() {
    if (typeof this.zContextOnCall == "function") {
      this.zContextOnCall("close");
    }
  }
}
</script>
